package com.whfp.afs330h_sdk.afs330h;


import android.app.Application;

import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleMtuChangedCallback;
import com.clj.fastble.data.BleDevice;
import com.whfp.afs330h_sdk.callback.ConnectCallback;
import com.whfp.afs330h_sdk.callback.DeviceCallback;
import com.whfp.afs330h_sdk.utils.DeviceUtils;
import com.whfp.afs330h_sdk.zx;


public final class BtManagerImpl implements BtManager {

    private static final Object lock = new Object();
    private static volatile BtManagerImpl instance;
    private static DeviceUtils deviceUtils;

    private BtManagerImpl() {
    }

    public static void registerInstance(Application application) {
        if (instance == null) {
            synchronized (lock) {
                if (instance == null) {
                    instance = new BtManagerImpl();
                }
            }
        }
        deviceUtils = DeviceUtils.getInstance(application);
        zx.setAfs330hManager(instance);
    }

    @Override
    public void setMtu(BleDevice bleDevice, int mtu, BleMtuChangedCallback callback) {
        deviceUtils.setMtu(bleDevice, mtu, callback);
    }

    @Override
    public void connectDevice(String address, ConnectCallback callback) {
        deviceUtils.connectDevice(address, callback);
    }

    @Override
    public void connectDeviceNoParsing(String mac, int deviceType, ConnectCallback callback) {
        deviceUtils.connectDeviceNoParsing(mac, deviceType, callback);
    }

    @Override
    public void connectDeviceNoParsing(String mac, String refType, ConnectCallback callback) {
        deviceUtils.connectDeviceNoParsing(mac, refType, callback);
    }

    @Override
    public void getDeviceStatus(BleDevice bleDevice, boolean isJCSJKZT) {
        deviceUtils.getDeviceStatus(bleDevice, isJCSJKZT);
    }

    @Override
    public BleDevice getCurrentDevice() {
        return deviceUtils.getCurrentDevice();
    }

    @Override
    public void disConnect(BleDevice bleDevice) {
        BleManager.getInstance().disconnect(bleDevice);
    }

    @Override
    public void openNotify(BleDevice bleDevice, DeviceCallback deviceCallback) {
        deviceUtils.openNotify(bleDevice, deviceCallback);
    }

    @Override
    public void openNotifyEHY(BleDevice bleDevice, DeviceCallback deviceCallback) {
        deviceUtils.openNotifyEHY(bleDevice, deviceCallback);
    }

    @Override
    public boolean stopNotify(BleDevice bleDevice) {
        return deviceUtils.stopNotify(bleDevice);
    }

    @Override
    public void startTest(BleDevice bleDevice, String code) {
        deviceUtils.startTest(bleDevice, code);
    }

    @Override
    public void startTestBarCode(BleDevice bleDevice, String barcode) {
        deviceUtils.startTestBarCode(bleDevice, barcode);
    }

    @Override
    public void startTestQrCode(BleDevice bleDevice, String qrCode) {
        deviceUtils.startTestQrCode(bleDevice, qrCode);
    }

    @Override
    public void readDeviceProject(BleDevice bleDevice, boolean isFGZJXM) {
        deviceUtils.readDeviceProject(bleDevice, isFGZJXM);
    }

    @Override
    public void loadCloudProject(BleDevice bleDevice, boolean isFGZJXM, String projectData) {
        deviceUtils.loadCloudProject(bleDevice, isFGZJXM, projectData);
    }

    @Override
    public void deleteDeviceProject(BleDevice bleDevice, String barCode) {
        deviceUtils.deleteDeviceProject(bleDevice, barCode);
    }

    @Override
    public void quitApply() {
        deviceUtils.quitApply();
    }

    @Override
    public void disconnectAllDevice() {
        deviceUtils.disconnectAllDevice();
    }

    @Override
    public void openBlue() {
        deviceUtils.openBlue();
    }

    @Override
    public boolean isBlueEnable() {
        return deviceUtils.isBlueEnable();
    }

    @Override
    public String base64Decode(String str) throws Exception {
        return deviceUtils.base64Decode(str);
    }


}
